package com.xunyin.enums;

/**
 * @author jthong
 * @Description:指令前缀
 * @Version 1.0.0
 * @Date 2020/04/27 11:00
 */
public enum QRCodeTypeEnum {
    /***
     * 大门
     */
    GATE(1, "大门"),

    /***
     * 包间
     */
    ROOM(2, "包间");

    private final String name;
    private final int value;

    QRCodeTypeEnum(int value, String name) {
        this.name = name;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return value;
    }

    public static QRCodeTypeEnum parse(Integer value) {
        if (value == null) {
            return throwParseException(value);
        }
        for (QRCodeTypeEnum e : QRCodeTypeEnum.values()) {
            if (e.getValue() == value) {
                return e;
            }
        }
        return throwParseException(value);
    }

    private static QRCodeTypeEnum throwParseException(Integer value) {
        throw new IllegalArgumentException(value + " can not parse to " + QRCodeTypeEnum.class.getName());
    }

    public static String getNameByValue(Integer value) {
        if (value == null) {
            return "";
        }
        for (QRCodeTypeEnum e : QRCodeTypeEnum.values()) {
            if (e.getValue() == value) {
                return e.getName();
            }
        }
        return "";
    }
}
